package gui;

import game.GameDatabase;
import game.GameModel;
import gui.advertiser.AdvertiserGUI;
import gui.league.League;
import gui.spectate.SpectateGUI;

import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;

import domain.users.User;

import application.ArenaManager;

import technicalservices.error.ErrorHandler;

public class GUIFacade {

	private MainFrame mainFrame;

	public GUIFacade() {
		mainFrame = new MainFrame();
		
		// Create menu items:
		/*
		JMenuItem menuItemLeague = new JMenuItem("List Games");
		menuItemLeague.addActionListener(new ActionListener() {
			@Override
			public void actionPerformed(ActionEvent arg0) {
				ArenaManager.getInstance().listGames();
			}
		});
		mainFrame.addMenuItem("User", menuItemLeague);
		*/
		
		startLogin();
		//listGames();
	}
	
	
	public void setPanel(JPanel panel) {
		mainFrame.setPanel(panel);
	}
	
	public void showFrame() {
		mainFrame.setVisible(true);
	}

	public void setMenu(JMenuBar menuBar) {
		mainFrame.setMenu(menuBar);
	}
	
	public void resetMenu() {
		mainFrame.resetMenu();
	}

	public void addMenuItem(JMenu menuItem) {
		mainFrame.addMenuGroup(menuItem);
	}
	
	public void listGames() {
		mainFrame.setPanel(new DataList("Games", GameDatabase.getInstance().getGameDatabase()));
	}
	
	public void startGame(GameModel game) {
		mainFrame.startGame(game);
	}
	
	public void startLogin() {
		mainFrame.setPanel(new LoginFrame());
	}

	public void startSpectator() {
		mainFrame.setPanel(new SpectateGUI());
	}

	public void startAdvertiser() {
		mainFrame.setPanel(new AdvertiserGUI());
	}

	public void startOperator() {
		ErrorHandler.getInstance().showError("Operator: Not yet implemented!");
	}

	public void startLeagueOwner() {
		mainFrame.setPanel(new League());
		//ErrorHandler.getInstance().showError("League Owner: Not yet implemented!");
	}

	public void startPlayer() {
		listGames();
	}

	private int amount;

	public void addAmount(int amount) {
		this.amount += amount;
	}

	public int getAmount() {
		return amount;
	}

	public void spectateMatch(String server) {
		System.out.println("Connecting to server " + server);
	}

}
